﻿@using Eqwww.Code
@model Eqwww.Web.Areas.SystemManage.Models.Role.IndexViewModel

@{
    ViewData["Title"] = "Index";
    Layout = "~/Views/Shared/_ManageIndexLayout.cshtml";
}



<div id="eq-operate">
    <div class="mdui-appbar mdui-appbar-fixed mdui-shadow-1">
        <div class="mdui-toolbar mdui-color-white">
            <a class="eq-operate-cancel-select" href="javascript:;" mdui-tooltip="{content: '取消选择'}">
                已选中 <b>1</b> 项
            </a>

            <module-buttons class="mdui-btn-group mdui-hidden-sm-down" buttons="@ViewBag.SelectedButtons"></module-buttons>

            <module-buttons class="mdui-hidden-md-up" buttons="@ViewBag.SelectedButtons" is-float="true"></module-buttons>

            <div class="mdui-toolbar-spacer"></div>
            <a class="eq-operate-cancel-select mdui-btn mdui-ripple" href="javascript:;">
                <i class="mdui-icon material-icons">do_not_disturb</i> 取消
            </a>
        </div>
    </div>
</div>
<div class="mdui-appbar mdui-shadow-1" id="xd-appbar">
    <div class="mdui-toolbar mdui-color-white">

        <a id="refreshBtn" class="eq-operate-cancel-select mdui-btn mdui-ripple mdui-ripple-black" href="javascript:;">
            <i class="mdui-icon material-icons">refresh</i> 刷新
        </a>


        <div class="mdui-toolbar-spacer"></div>


        <module-buttons class="mdui-btn-group" buttons="@ViewBag.InitialButtons"></module-buttons>


    </div>
</div>

<div class="mdui-container-fluid mdui-m-t-1">
    <div class="mdui-table-fluid">
        <table class="mdui-table" id="gridTable"></table>
        <div id="gridPager"></div>
    </div>
</div>


@section Scripts{
    <script>
        $(function () {
            
            gridTable();
        });



        function btn_create() {

            $.modalOpen({
                id: 'formCreate',
                title: '新建',
                url: '/SystemManage/Role/Create',
                width: '100%',
                height: '100%',
                callBack: function (iframeId) {
                    top.frames[iframeId].submitForm();
                }
            });
            return false;
        }

        function btn_edit() {
            var key = $('#gridTable').jqGridRowValue().Id;
            
            if (!key) {
                top.$.errorLayer('未选中任何行！');
                return false;
            }
            
            $.modalOpen({
                id: 'formEditButton',
                title: '修改',
                url: '/SystemManage/Role/Edit?id=' + key,
                width: '100%',
                height: '100%',
                callBack: function (iframeId) {
                    top.frames[iframeId].submitForm();
                }
            });
        }

        function btn_details() {
            var key = $('#gridTable').jqGridRowValue().Id;
            if (!key) {
                top.$.errorLayer('未选中任何行！');
                return false;
            }
            $.modalOpen({
                id: 'Details',
                title: '查看',
                url: '/SystemManage/Role/Details?id=' + key,
                width: '100%',
                height: '100%',
                isback: true,
                hideConfirmBtn: true,
                btn: null
            });
        }

        function btn_delete() {
            var key = $('#gridTable').jqGridRowValue().Id;
            if (!key) {
                top.$.errorLayer('未选中任何行！');
                return false;
            }
            var isSystem = $('.eq-list-table').GridSelectedOptionValue('data-issystem');

            if (isSystem == 'True') {
                top.$.errorLayer('系统角色不允许删除！');
                return false;
            }
            $.deleteForm({
                url: '/SystemManage/Role/Delete',
                param: { id: key },
                success: function () {
                    window.location.reload();
                }
            })
        }

        function btn_strategorymanage() {
            var key = $('#gridTable').jqGridRowValue().Id;
            
            if (!key) {
                top.$.errorLayer('未选中任何行！');
                return false;
            }
           
            $.modalOpen({
                id: 'formStrategoryManage',
                title: '策略授权',
                url: '/SystemManage/Role/StrategoryManage?id=' + key,
                width: '100%',
                height: '100%',
                callBack: function (iframeId) {
                    top.frames[iframeId].submitForm();
                }
            });
        }

        function btn_claims() {
            var key = $('#gridTable').jqGridRowValue().Id;
            
            if (!key) {
                top.$.errorLayer('未选中任何行！');
                return false;
            }
            
            $.modalOpen({
                id: 'RoleClaims',
                title: '声明授权',
                url: '/SystemManage/Role/Claims?roleId=' + key,
                width: '100%',
                height: '100%',
                callBack: function (iframeId) {
                    top.frames[iframeId].submitForm();
                }
            });
        }


        function gridTable() {
            var $gridList = $("#gridTable");
            $gridList.dataGrid({
                url: '/SystemManage/Role/GridJson',
                mtype: "GET",
                datatype: "json",
                sortname: 'CreateTime',
                sortorder: 'DESC',
                colModel: [
                    { label: 'Id', name: 'Id', key: true, hidden: true },
                    { label: '名称', name: 'ShowName', width: 150 },
                    { label: '编码', name: 'Name', width: 100 },
                    {
                        label: '系统', name: 'IsSystem', width: 100, formatter: function (cellValue) {
                            return getBoolIcon(cellValue);
                        }
                    },
                    { label: '排序码', name: 'SortCode', width: 100 },
                    { label: '创建人', name: 'CreateUserName', width: 100 },
                    {
                        label: '创建时间', name: 'CreateTime', width: 110, formatter: 'date', formatoptions: {
                            srcformat: 'Y-m-d', newformat: 'Y-m-d'
                        }
                    }

                ],
                viewrecords: true,
                height: getGridHeight() - 36,
                rowNum: 20,
                pager: "#gridPager",
                shrinkToFit: true
            });

            
            $('#refreshBtn').click(function () {
                window.location.reload();
            })
        }

        function btn_updateissystem() {
            var key = $('#gridTable').jqGridRowValue().Id;
            if (!key) {
                top.$.errorLayer('未选中任何行！');
                return false;
            }

            $.deleteForm({
                prompt: '确定提升为系统角色吗？',
                url: '/SystemManage/Role/UpdateIsSystem',
                param: { id: key },
                success: function () {
                    window.location.reload();

                }
            })
        }

        function btn_updateisnotsystem() {
            var key = $('#gridTable').jqGridRowValue().Id;
            if (!key) {
                top.$.errorLayer('未选中任何行！');
                return false;
            }

            $.deleteForm({
                prompt: '确定取消系统角色吗？',
                url: '/SystemManage/Role/UpdateIsNotSystem',
                param: { id: key },
                success: function () {
                    window.location.reload();

                }
            })
        }

    </script>
}